<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>事件处理</title>
  <script src="https://unpkg.com/react@16/umd/react.development.js"></script>
  <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
  <!-- 生产环境中不建议使用 -->
  <script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
</head>

<body>
  <!-- 容器 -->
  <div id="test"></div>

  <script type="text/babel">
    class Demo extends React.Component {
      save = (event) => {
        // 禁止表单默认提交 - 刷新操作
        event.preventDefault();
        
        let { name, password } = this;
        alert(`表单中姓名为${name.value}，密码是${password.value}`)
      }
      render() {
        return (
          <form onSubmit={this.save}>
            姓名： <input ref={c => this.name = c} type="text" name="name" />
            密码： <input ref={c => this.password = c} type="password" name="password" />
            <button>按钮</button>
          </form>
        )
      }
    }

    //2.渲染虚拟DOM到页面
    ReactDOM.render(<Demo a="1" b="2" />, document.getElementById("test"))
  </script>

</body>

</html>
